# from django.contrib import admin
#
# from . import models
# from celery_tasks.html.tasks import generate_static_sku_detail_html
#
# """
# 当运营人员在admin站点保存商品信息时,应该触发生成商品静态页面的异步任务,那么就需要调整admin站点保存和删除商品信息时的行为
#
# 这里django调用admin站点管理类的save_model()方法和delete_model()方法,即在保存或删除数据时调用异步任务即可,注意在admin注册
# """
#
#
# """
# class SKUAdmin(admin.ModelAdmin):
#     def save_model(self, request, obj, form, change):
#         obj.save()
#         generate_static_sku_detail_html.delay(obj.id)
#
#
# class SKUSpecificationAdmin(admin.ModelAdmin):
#     def save_model(self, request, obj, form, change):
#         obj.save()
#         generate_static_sku_detail_html.delay(obj.sku.id)
#
#     def delete_model(self, request, obj):
#         sku_id = obj.sku.id
#         obj.delete()
#         generate_static_sku_detail_html.delay(sku_id)
#
#
# class SKUImageAdmin(admin.ModelAdmin):
#     def save_model(self, request, obj, form, change):
#         obj.save()
#         generate_static_sku_detail_html.delay(obj.sku.id)
#
#         # 设置sku默认图片
#         sku = obj.sku
#         if not sku.default_image_url:
#             sku.default_image_url = obj.image_url
#             sku.save()
#
#     def delete_model(self, request, obj):
#         sku_id = obj.sku.id
#         obj.delete()
#         generate_static_sku_detail_html.delay(sku_id)
# """
#
#
# class SKUAdmin(admin.ModelAdmin):
#     # 定义列表页的属性
#     list_display = ['id', 'name', 'price']
#
#     # 定义编辑页的属性
#     # 重写保存、删除方法
#     def save_model(self, request, obj, form, change):
#         # 当新增、修改对象时，这个方法会执行
#         super().save_model(request, obj, form, change)
#         # 生成静态文件
#         generate_static_sku_detail_html.delay(obj.id)
#
#     def delete_model(self, request, obj):
#         # 当删除对象时，这个方法会执行
#         super().delete_model(request, obj)
#
#
# admin.site.register(models.GoodsCategory)
# admin.site.register(models.GoodsChannel)
# admin.site.register(models.Goods)
# admin.site.register(models.Brand)
# admin.site.register(models.GoodsSpecification)
# admin.site.register(models.SpecificationOption)
# admin.site.register(models.SKU, SKUAdmin)
# admin.site.register(models.SKUSpecification)
# admin.site.register(models.SKUImage)
#
#
